/*
 *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.base.redis.strategy;

import com.baomidou.lock.LockKeyBuilder;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.cache.interceptor.KeyGenerator;

/**
 * 自定义分布式锁key生成规则.
 *
 * @author zengdegui
 * @since 2024/07/06 16:45
 */
@Slf4j
public class CustomLockKeyBuilder implements LockKeyBuilder {

    @Resource
    private KeyGenerator keyGenerator;

    @Override
    public String buildKey(MethodInvocation invocation, String[] definitionKeys) {
        final String key = this.keyGenerator.generate(invocation.getMethod().getDeclaringClass().getName(), invocation.getMethod(),
            invocation.getArguments()).toString();
        log.info("自定义分布式锁key, key={}", key);
        return key;
    }
}
